<?php
namespace Modules\User\Library;

use Phalcon\Di;
use Modules\Xunsearch\Library\Xunsearch;
use Modules\User\Entity\User;

class Search
{
    public static function xunsearchGenerateProjectFile()
    {
        $di = Di::getDefault();
        $field = $di->getShared('entityManager')->field('user');
        $state = Xunsearch::formFieldToIni($field, WEB_CODE . '_user');
        if ($state) {
            return true;
        } else {
            return false;
        }
    }

    public static function source($page = 1){
        $data = User::find([
            'sort' => [
                'changed' => -1,
            ],
            'limit' => 30,
            'skip' => 30 * ($page - 1),
        ]);
        return $data;
    }

    public static function total(){
        return User::count();
    }
}